<?php
namespace app\activityNew\controller;
use think\admin\Controller;
use think\admin\service\AdminService;
use think\admin\helper\QueryHelper;
use app\activityNew\model\ImsEweiShopActivity;
use think\admin\model\SystemAuth;
use think\admin\model\SystemBase;
use think\admin\model\SystemUser;
use think\facade\Request;

class Index extends Controller
{
    public function index()
    {
		
        /*! 判断当前用户的登录状态 */
        $this->login = AdminService::isLogin();
        /*! 菜单为空且未登录跳转到登录页 */
        if (empty($this->menus) && empty($this->login)) {
            // $this->redirect(sysuri('admin/login/index'));
        } else {
			ImsEweiShopActivity::mQuery()->layTable(function () {
            $this->title = '活动管理';
        }, function (QueryHelper $query) {
            // 加载对应数据列表
           $query->where(['delete' => 0]);

            // 数据列表搜索过滤
            $query->like('actname#keywords');
			//echo $query->buildSql();exit();
        });


            $this->fetch();
        }
    }

	 protected function _index_page_filter(&$data){
		//echo 1111;
	 }



    /**
     * 添加
     * @auth true
     */
    public function add()
    {
        
        ImsEweiShopActivity::mForm('form');
    }

    /**
     * 编辑
     * @auth true
     */
    public function edit()
    {
        ImsEweiShopActivity::mForm('form');
    }

    /**
     * 删除
     * @auth true
     */
    public function remove()
    {
        $this->_checkInput();
        $ids_srt = Request::param('id');
        $ids_arr = array_unique(array_filter(explode(',', $ids_srt)));

        $goodsCount = ImsEweiShopActivity::mk()->where('id','in',$ids_arr)->undate(['delete'=>1]);
       
        //ImsEweiShopActivity::mDelete();
    }

 

    /**
     * 修改状态
     * @auth true
     */
    public function status()
    {
		if(Request::param('actstatus')==1){
            $where = [
                'actstatus' => 1,
                'delete' => 0,
            ];
            $adCount = ImsEweiShopActivity::mk()->where($where)->count();
            if ($adCount>0) {
                $this->error('已有启动活动不可多启动！');
            }
		}
        ImsEweiShopActivity::mSave($this->_vali([
            'actstatus.in:1,2'  => '状态值范围异常！',
            'actstatus.require' => '状态值不能为空！',
        ]));
    }
}
